home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_484 / bootpic / bootpic.asm < prev    next >
Assembly Source File  |  1992-05-06  |  35KB  |  1,013 lines

  1. ********************************************************************************
  2. *                                                                              *
  3. *                                BootPic V1.0                                  *
  4. *                                (source-code)                                 *
  5. *                                                                              *
  6. *  Author:     Andreas Ackermann                                               *
  7. *  Assembler:  Devpac V2.14D                                                   *
  8. *  Date:       from 21.3. to 31.3. 1991                                        *
  9. *  Develloped under Kickstart V1.2                                             *
  10. *                                                                              *
  11. *  [see doc-file for further information].                                     *
  12. *                                                                              *
  13. * The whole programm is split in two parts:                                    *
  14. * 1st we look what the user wants, then we remove or install BootPic in the    *
  15. * way it is requested.                                                         *
  16. * The 2nd part, which is installed resident, is responsible for showing the    *
  17. * picture.                                                                     *
  18. *                                                                              *
  19. ********************************************************************************
  20.  
  21.         incdir  "Include:"
  22.         include "graphics/graphics_lib.i"
  23.         include "exec/exec_lib.i"
  24.         include "libraries/dos_lib.i"
  25.         include ":bootpic/bpic_special.i"
  26.  
  27.  
  28.         movem.l d0/a0,-(sp)            ;save commandline parameters
  29.         move.l  4.w,a6
  30.         sub.l   a1,a1
  31.         jsr     _lvoFindTask(a6)       ;find structure of our task
  32.         move.l  d0,a4
  33.         tst.l   pr_CLI(a4)             ;WB?
  34.         bne.s   run
  35. fromWorkbench
  36.         lea     pr_MsgPort(a4),a0      ;if WB we must wait for startup-msg
  37.         jsr     _lvowaitport(a6)
  38.         lea     pr_MsgPort(a4),a0
  39.         jsr     _lvogetmsg(a6)
  40.         move.l  d0,wbenchmsg          ;save message !!
  41.  
  42. run     movem.l (sp)+,d0/a0            ;return commandline parms
  43.         bsr.s   _main                  ;call our programm
  44.         tst.l   wbenchmsg              ;run from WB ?
  45.         beq.s   _exit                  ;no => CLI
  46.         move.l  4.w,a6
  47.         jsr     _lvoforbid(a6)
  48.         move.l  wbenchmsg(pc),a1        ;return message
  49.         jsr     _lvoreplymsg(a6)
  50. _exit
  51.         clr.l   d0                      ;no returncode
  52.         rts                             ;the end
  53.  
  54. allmeml      equ     $654       ;length of structure AND resident code
  55.  
  56. * two macros for pc-relative code
  57.  
  58. elea   macro             ;Extended LEA   elea xx(ax),xx(ax)
  59.         lea     \1,a0
  60.         move.l  a0,\2
  61.         endm
  62. emove  macro             ;Extended MOVE  move.l xx,xx(pc)
  63.         lea     \2,a0
  64.         move.l  \1,(a0)
  65.         endm
  66.  
  67. _main
  68.         movem.l d0/a0,-(sp)        ;save parms again
  69.         move.l  4.w,a6
  70.         lea     gfxname(pc),a1
  71.         jsr     _lvooldopenlibrary(a6)
  72.         move.l  d0,gfxbase
  73.         lea     dosname(pc),a1
  74.         jsr     _lvooldopenlibrary(a6)  ;open gfx+dos
  75.         move.l  d0,dosbase
  76.         move.l  d0,a6
  77.         jsr     _lvooutput(a6)      ;get handle of CLI
  78.         move.l  d0,whandle
  79.         tst.l   wbenchmsg           ;do we run under WB ? => open own window
  80.         beq.s   nowb
  81.         move.l  #oname,d1
  82.         move.l  #1005,d2
  83.         jsr     _lvoopen(a6)
  84.         move.l  d0,whandle          ;opened CON:-window
  85.         move.l  4.w,a6
  86.         move.l  #100,d0             ;get mem for readbuffer (of CON:-window)
  87.         move.l  #$10002,d1
  88.         jsr     _lvoallocmem(a6)
  89.         move.l  d0,conbuf
  90.         add.l   #8,a7
  91.         lea     welcome(pc),a2      ;introduce ourselves
  92.         bsr     stringout
  93. nextround
  94.         lea     ycom(pc),a2         ;tell the user what to do
  95.         bsr     stringout
  96.         move.l  dosbase(pc),a6
  97.         move.l  conbuf(pc),d2
  98.         move.l  whandle(pc),d1
  99.         move.l  #80,d3
  100.         jsr     _lvoread(a6)        ;read command parameters
  101.         move.l  conbuf(pc),a0       ;in d0 we get length of commandline
  102.         clr.l   remptr  ;clear our flags, cause this is a loop (when run
  103.         clr.b   camgf   ;from WB)
  104.         clr.l   fname
  105.         bra.s   parser
  106.  
  107. nowb
  108.         lea     welcome(pc),a2
  109.         bsr     stringout
  110.         movem.l (sp)+,d0/a0 ;get saved parms back from stack
  111. parser                      ;here we get both from CLI and WB: figure out
  112.                             ;what the user wants
  113.         subq.w  #1,d0       ;any parms ? no->usage
  114.         beq     noparms
  115.         clr.b   0(a0,d0.w)  ;zero-terminate it
  116. plop    bsr     getspcout
  117.         cmp.b   #'-',(a0)+
  118.         bne     noparms     ;no '-' in front of parameter
  119.         bclr.b  #5,(a0)     ;force uppercase
  120.         cmp.b   #'R',(a0)   ;get out -r
  121.         bne.s   noreset
  122.         move.b  #1,resetvar
  123.         add.l   #1,a0
  124.         bra.s   plop
  125. noreset cmp.b   #'E',(a0)   ;get out -e
  126.         bne.s   noremove
  127.         move.b  #1,mparm
  128.         move.b  #1,remptr
  129.         add.l   #1,a0
  130.         bra.s   plop
  131. noremove
  132.         cmp.b   #'S',(a0)  ;get out -s
  133.         bne.s   nostartup
  134.         move.b  #1,startup
  135.         add.l   #1,a0
  136.         bra.s   plop
  137. nostartup
  138.         cmp.b   #'L',(a0)  ;get out -l
  139.         bne.s   noload
  140.         move.b  #1,mparm
  141.         add.l   #1,a0
  142.         bsr     getspcout
  143.         move.l  a0,fname
  144. findspc add.l   #1,a0
  145.         cmp.b   #' ',(a0)
  146.         beq.s   terminate1
  147.         tst.b   (a0)
  148.         bne.s   findspc
  149.         beq     plop
  150. terminate1
  151.         clr.b  (a0)+
  152.         bra     plop
  153. noload  cmp.b   #'C',(a0)+ ;get out -c
  154.         bne.s   noparms    ;someone typed nosense after '-'
  155.         bsr     getspcout
  156.         moveq.w #2,d0
  157.         lea     konst(pc),a1    ;there we put the color
  158. cl      tst.b   (a0)
  159.         beq.s   ende
  160.         cmp.b   #' ',(a0)
  161.         beq.s   ende
  162.         sub.b   #48,(a0)
  163.         cmp.b   #10,(a0)
  164.         blt.s   no15
  165.         bclr.b  #5,(a0)
  166.         sub.b   #7,(a0)
  167. no15    and.b   #%1111,(a0)
  168.         move.b  (a0)+,(a1)+
  169.         dbf     d0,cl
  170.         bra     plop
  171.  
  172. getspcout
  173.         tst.b   (a0)       ;increase a0 till we find a space or zero
  174.         beq.s   wrt
  175.         cmp.b   #' ',(a0)+
  176.         beq     getspcout
  177.         sub.l   #1,a0
  178.         rts
  179. wrt     add.l   #4,sp
  180.         bra.s   ende
  181. noparms lea     use(pc),a2
  182.         bra     noopen
  183. ende    tst.b   mparm
  184.         beq.s   noparms
  185.         move.l  4.w,a6      ;the parms were correct, so let's kill a possibly
  186.         move.l  546(a6),a3  ;installed BootPic at any rate
  187.         tst.l   546(a6)
  188.         beq     notinstalled
  189. chknxt  move.l  LN_NAME(a3),a0
  190.         cmp.l   #'BPic',(a0)        ;go through memlist till we find BootPic
  191.         beq.s   bpicfound           ;or till the end
  192.         tst.l   (a3)                ;[tst.l  LN_SUCC(a3)]
  193.         beq     notinstalled
  194.         move.l  (a3),a3             ;[move.l LN_SUCC(a3),a3] next node
  195.         bra.s   chknxt
  196. bpicfound               ;we found BootPic !!!
  197.         tst.b   startup ;check for -s flag: if not set let's remove BootPic
  198.         beq.s   remove
  199.         lea     stext(pc),a2    ;tell the user that BPic is installed
  200.         bra     noopen          ;return
  201. remove  jsr     _lvoforbid(a6)  ;in a3 we still hold the memlist-node of BPic
  202.         tst.l   LN_PRED(a3)     ;is there anyone before ?
  203.         beq.s   nopred          ;if not, we're first
  204.         move.l  LN_PRED(a3),a0  ;move our successor(or zero) to the successor
  205.         move.l  (a3),(a0)       ;of our predecessor
  206. tstsuc  tst.l   (a3)            ;is there any successor ?
  207.         beq.s   predok          ;no, everything ok
  208.         move.l  (a3),a1         ;if so we must move its address to the
  209.         move.l  a0,LN_PRED(a1)  ;successor's address of our predecessor
  210.         bra.s   predok
  211. nopred  move.l  (a3),546(a6)    ;if we're first, we must write the start of
  212.         sub.l   a0,a0           ;memlist into sysbase->kickmemptr
  213.         bra.s   tstsuc
  214. predok                          ;we switched off multitasking, so we can free
  215.         move.w  LN_NAME+4(a3),d3;the allocated memory already now (numentries)
  216.         subq.w  #1,d3           ;LN_NAME+4 = ML_NUMENTRIES
  217.         add.l   #LN_NAME+6,a3   ;start of memorypointer table
  218. fagain  move.l  (a3)+,a1        ;startaddress
  219.         move.l  (a3)+,d0        ;length
  220.         jsr     _lvofreemem(a6) ;free it
  221.         dbf     d3,fagain       ;usually twice (dbf loop for reasons of compa-
  222.                                 ;tibilty to higher versions that might follow)
  223.         move.l  550(a6),a3      ;kicktagptr to a3
  224. nentry  move.l  (a3),a0
  225.         move.l  rt_name(a0),a0
  226.         cmp.l   #'BPic',(a0)    ;check first resident structure for BPic
  227.         beq.s   bpicf2
  228.         move.l  a3,a4           ;save actual restabptr
  229.         add.l   #4,a3           ;next entry
  230.         move.l  (a3),d0 ;no more entrys ?! but we found BPic's memory and now
  231.         beq.s   finito  ;we found not its resident structure => fatal error !
  232.         btst.l  #$1f,d0 ;next entry or pointer to next restab
  233.         beq.s   nentry
  234.         bclr.l  #$1f,d0 ;clear highbit
  235.         move.l  d0,a3   ;lets' check next residenttable structure
  236.         bra.s   nentry
  237.  
  238. finito  lea.l   fail(pc),a2     ;if we run here there was a fatal error
  239.         jsr     _lvopermit(a6)
  240.         bra     noopen
  241.  
  242. bpicf2  cmp.l   550(a6),a3      ;is our actual restab the same as in kicktagptr?
  243.         bne.s   linkout         ;if not we have a predecessor (held in a4)
  244.         move.l  4(a3),d0        ;move our sucessor (or zero) to kicktagptr
  245.         bclr.l  #$1f,d0         ;clear highbit
  246.         move.l  d0,550(a6)
  247.         bra.s   ready
  248. linkout move.l  4(a3),4(a4)     ;put our successor (or zero) to our predecessor
  249. ready
  250.         jsr     -612(a6)        ;calc checksum (kicksumdata)
  251.         move.l  d0,554(a6)
  252.         jsr     _lvopermit(a6)
  253.         lea     remt(pc),a2     ;print out that we removed it
  254.         bsr     stringout
  255.         sub.l   a2,a2
  256.         tst.b   remptr          ;check for -e: was that all we should do?
  257.         bne     noopen          ;yes->return, no-> let's try to load the picture
  258. notinstalled
  259.         lea     nrem(pc),a2
  260.         tst.b   remptr          ;test if user typed -e;but BPic was not there
  261.         bne     noopen          ;return and let's tell him if so
  262.  
  263.  
  264.         move.l  dosbase(pc),a6
  265.         move.l  fname(pc),d1
  266.         move.l  #1005,d2
  267.         jsr     _lvoopen(a6)    ;try to open file
  268.         lea     fnf(pc),a2
  269.         move.l  d0,handle
  270.         beq     noopen          ;if error let's tell the user
  271.  
  272.         move.l  4.w,a6
  273.         move.l  #1000,d0
  274.         move.l  #$10002,d1      ;chip+clear
  275.         jsr     _lvoallocmem(a6);get memory for readbuffer of file
  276.         lea     nomem(pc),a2
  277.         move.l  d0,buffer
  278.         beq     nobufmem
  279.         move.l  #allmeml,d0
  280.         move.l  #$10001,d1      ;memf_public+clear
  281.         jsr     _lvoallocmem(a6);get memory for our special structure
  282.         move.l  d0,a5           ;from now on this pointer is to be found in a5
  283.         beq     nostruktmem
  284.  
  285.         move.l  dosbase(pc),a6
  286.         move.l  handle(pc),d1
  287.         move.l  buffer(pc),d2
  288.         moveq.l #12,d3
  289.         jsr     _lvoread(a6)    ;read header of file
  290.         move.l  buffer(pc),a4   ;buffer to address-register so that we can use
  291.         lea     nilbm(pc),a2    ;offsets
  292.         cmp.l   #'FORM',(a4)
  293.         bne     noiff           ;no IFF->error
  294.         cmp.l   #'ILBM',8(a4)
  295.         bne     noiff           ;not ILBM->error
  296. getchunk
  297.         move.l  handle(pc),d1
  298.         moveq.l #8,d3
  299.         jsr     _lvoread(a6)    ;read header of chunk
  300.         lea     bnf(pc),a2      ;4 Bytes code word + 4 Bytes length
  301.         tst.l   d0              ;end of file ? but we didn't find BODY
  302.         beq     noiff           ;->error
  303.         cmp.l   #'BODY',(a4)
  304.         beq     bodyfound
  305.         cmp.l   #'CMAP',(a4)
  306.         beq     cmapfound
  307.         cmp.l   #'CAMG',(a4)
  308.         beq     camgfound
  309.         cmp.l   #'BMHD',(a4)
  310.         beq     bmhdfound
  311.         bsr     rcdata         ;if we get here it wasn't any chunk we need
  312.         bra.s   getchunk
  313. bodyfound
  314.  
  315.         move.l  4.w,a6
  316.         move.l  4(a4),d0
  317.         addq.l  #4,d0
  318.         move.l  d0,ml_len2(a5)
  319.         addq.l  #8,d0           ;allocmem rounds down by 8 bytes
  320.         move.l  #$10002,d1
  321.         jsr     _lvoallocmem(a6);memory for BODY-chunk
  322.         lea     nmfb(pc),a2
  323.         move.l  d0,memptr
  324.         beq     noiff
  325.         move.l  d0,d2
  326.         move.l  dosbase(pc),a6
  327.         bsr     rcdata          ;read BODY in
  328.         move.l  4.w,a6
  329.         move.l  4(a4),d0
  330.         add.l   #12,d0
  331.         moveq.l #4,d1
  332.         jsr     _lvoallocmem(a6);fastmem ?
  333.         move.l  d0,a1
  334.         tst.l   d0
  335.         beq.s   nofast          ;if there let's copy the BODY to it !
  336.         move.l  d0,a3
  337.         move.l  memptr(pc),a0
  338.         move.l  4(a4),d1
  339.         lsr.l   #2,d1
  340. bloop   move.l  (a0)+,(a1)+     ;copy BODY
  341.         dbf     d1,bloop
  342.         move.l  4(a4),d0
  343.         add.l   #12,d0
  344.         move.l  memptr(pc),a1
  345.         jsr     _lvofreemem(a6) ;free old chipmem
  346.         bra.s   memfreed
  347. nofast  move.l  memptr(pc),a3
  348. memfreed
  349.         move.l  a3,ml_addr2(a5)
  350.         tst.b   camgf           ;did we find CAMG ?
  351.         bne.s   noham
  352.         lea     ncamg(pc),a2    ;let's tell the user that we improvise
  353.         bsr     stringout
  354.         cmp.w   #353,vp_dwidth(a5)      ;wider than 352 bytes?
  355.         blt.s   nohires                 ;it must be hires
  356.         add.w   #$8000,vp_modes(a5)
  357. nohires
  358.         cmp.w   #283,vp_dheight(a5)     ;...
  359.         blt.s   nolace
  360.         add.w   #$4,vp_modes(a5)
  361. nolace
  362.         cmp.w   #6,depth(a5)        ;HAM and Halfbright work with 6 planes
  363.         bne.s   noham
  364.         add.w   #$800,vp_modes(a5)  ;I say it's HAM !!!
  365. noham
  366.         move.l  a5,strktptr         ;put the pointer to our structure into the
  367.         lea     suc(pc),a2          ;resident code (will be copied later on! )
  368.         move.l  gfxbase(pc),a6
  369.         lea     view(a5),a1         ;init all we need to show the picture
  370.         jsr     _lvoinitview(a6)
  371.         move.w  vp_modes(a5),v_modes(a5)
  372.         elea    viewport(a5),v_viewport(a5)
  373.         lea     bitmap(a5),a0
  374.         move.w  depth(a5),d0
  375.         move.w  bmw(a5),d1
  376.         move.w  bmh(a5),d2
  377.         jsr     _lvoinitbitmap(a6)
  378.         lea.l   rasinfo(a5),a0
  379.         elea    bitmap(a5),ri_bitmap(a5)
  380.         elea     rasinfo(a5),vp_rasinfo(a5)
  381.         move.w  vp_modes(a5),d0    ;if overscan move the picture to top left
  382.         move.w  #320,d1            ;corner
  383.         btst.l  #$f,d0
  384.         beq.s   nohires2
  385.         lsl.w   #1,d1
  386. nohires2
  387.         neg.w   d1
  388.         add.w   vp_dwidth(a5),d1
  389.         bpl.s   doit1
  390.         clr.w   d1
  391. doit1   lsr.w   #1,d1
  392.         sub.w   d1,v_dxoffset(a5)
  393.         move.w  #256,d1
  394.         btst.l  #$2,d0
  395.         beq.s   nolace2
  396.         lsl.w   #1,d1
  397. nolace2 neg.w   d1
  398.         add.w   vp_dheight(a5),d1
  399.         bpl.s   doit
  400.         clr.w   d1
  401. doit    lsr.w   #1,d1
  402.         sub.w   d1,v_dyoffset(a5)
  403.  
  404.         lea     idendity(a5),a0         ;copy code into allocated memory
  405.         lea     begincopy(pc),a1
  406.         move.w  #endcopy-begincopy-1,d0
  407. idlop   move.b  (a1)+,(a0)+
  408.         dbf     d0,idlop
  409.  
  410.         move.l  a5,ml_addr1(a5)        ;intialize resident structure
  411.         move.l  #allmeml-20,ml_len1(a5)
  412. fillout move.w  #rtc_matchword,rt_matchword(a5)
  413.         elea    rt_matchword(a5),rt_matchtag(a5)
  414.         elea    rt_SIZE(a5),rt_endskip(a5)
  415.         move.b  #1,rt_flags(a5)
  416.         move.b  #-1,rt_pri(a5)
  417.         elea    id_name(a5),rt_name(a5)
  418.         elea    id_string(a5),rt_idstring(a5)
  419.         elea    code(a5),rt_init(a5)
  420.  
  421.         move.w  #2,ml_numentries(a5)  ;init memlist structure
  422.         elea    id_name(a5),myln_name(a5)
  423.         move.b  #nt_memory,myln_type(a5)
  424.  
  425. login
  426.         move.l  4.w,a6
  427.         jsr     _lvoforbid(a6)      ;let's write ourselves into sysbase
  428.         move.l  546(a6),a1          ;kickmemptr
  429.         tst.l   546(a6)
  430.         beq.s   nixda               ;we always use first place and put
  431.         move.l  a1,myln_succ(a5)      ;any things that were before us behind us
  432.         elea    myln_succ(a5),4(a1)   ;[predecessor]
  433.  
  434. nixda   elea    myln_succ(a5),546(a6) ;and now for kicktagptr
  435.         move.l  a5,restab(a5)
  436.         move.l  550(a6),d0
  437.         beq.s   nomtag
  438.         bset    #$1f,d0
  439.         move.l  d0,restab+4(a5)
  440.  
  441. nomtag  elea    restab(a5),550(a6)
  442.         jsr     -612(a6)            ;kicksumdata
  443.         move.l  d0,554(a6)          ;fill in kickchecksum
  444.         jsr     _lvopermit(a6)
  445.  
  446.         tst.b   resetvar            ;does the user want to reset the machine?
  447.         beq.s   nostruktmem
  448.         lea     cod(pc),a5
  449.         lea     2,a4
  450.         jsr     _lvosupervisor(a6) ;that's all ...
  451.         cnop    0,4
  452. cod     reset
  453.         jmp     (a4)
  454. noiff                               ;here we run if there's an error while
  455.         move.l  4.w,a6              ;loading
  456.         move.l  a5,a1
  457.         move.l  #allmeml,d0
  458.         jsr     _lvofreemem(a6)
  459. nostruktmem                         ;not enough memory for our structure
  460.         move.l  4.w,a6
  461.         move.l  buffer(pc),a1
  462.         move.l  #1000,d0
  463.         jsr     _lvofreemem(a6)
  464. nobufmem                            ;not enough mem for diskbuffer
  465.         move.l  dosbase(pc),a6
  466.         move.l  handle(pc),d1
  467.         jsr     _lvoclose(a6)
  468. noopen  ;move.l  dosbase(pc),a6
  469.         move.l  a2,d2
  470.         beq.s   noerr
  471.         bsr     stringout
  472. noerr   tst.l   wbenchmsg
  473.         beq.s   nowb2           ;if run from WB we read some characters
  474.         lea     endwb(pc),a2    ;if length=1 the user just typed RETURN
  475.         bsr     stringout       ;so we let him type in the commandline again
  476.         move.l  dosbase(pc),a6
  477.         move.l  conbuf(pc),d2
  478.         move.l  whandle(pc),d1
  479.         moveq.l #2,d3
  480.         jsr     _lvoread(a6)
  481.         subq.w  #1,d0
  482.         beq     nextround
  483.         move.l  whandle(pc),d1  ;if there was typed more than RETURN we
  484.         jsr     _lvoclose(a6)   ;close the window free the memory and
  485.         move.l  4.w,a6          ;return
  486.         move.l  conbuf(pc),a1
  487.         move.l  #100,d0
  488.         jsr     _lvofreemem(a6)
  489. nowb2   move.l  4.w,a6                  ;close libs
  490.         move.l  dosbase(pc),a1
  491.         jsr     _lvocloselibrary(a6)
  492.         move.l  gfxbase(pc),a1
  493.         jsr    _lvocloselibrary(a6)
  494.         rts
  495.  
  496. **//** SUBs + chunk-reading routines
  497.  
  498. * print out a zero-termintated string of which the start is found in a2
  499. stringout
  500.         move.l  a2,d2
  501.         move.l  #-1,d3
  502. p1      addq.l  #1,d3
  503.         tst.b   (a2)+
  504.         bne.s   p1
  505.         move.l  whandle,d1
  506.         move.l  a6,-(a7)
  507.         move.l  dosbase(pc),a6
  508.         jsr     _lvowrite(a6)
  509.         move.l  (sp)+,a6
  510.         rts
  511.  
  512. * read in one chunk
  513. rcdata
  514.         move.l  4(a4),d3
  515.         move.l  handle,d1
  516.         jsr     _lvoread(a6)
  517.         rts
  518.  
  519. * get colormap [format see at getcols ! ]
  520. cmapfound
  521.         move.l  4(a4),d4
  522.         elea    coltab(a5),d2
  523.         bsr     rcdata
  524.         move.l  buffer(pc),d2
  525.         lea     coltab(a5),a0
  526. gcol    move.b  (a0),d0
  527.         lsr.b   #4,d0
  528.         and.b   #%1111,d0
  529.         move.b  d0,(a0)+
  530.         dbf     d4,gcol
  531.         bra getchunk
  532.  
  533. * here are the viewmodes
  534. camgfound
  535.         bsr     rcdata
  536.         move.w  modes+2(a4),vp_modes(a5)    ;get the viewmodes
  537.         move.b  #1,camgf
  538.         bra     getchunk
  539. * get the dimensions of the picture
  540. bmhdfound
  541.         bsr     rcdata
  542.         move.l  w(a4),bmw(a5)   ;w+h are .w so .l is enough for both
  543.         move.b  nplanes(a4),depth+1(a5)
  544.         move.b  masking(a4),mask(a5)
  545.         lea ncomp(pc),a2
  546.         tst.b   compression(a4);we won't load compressed pictures
  547.         beq noiff
  548.         move.w  pagewidth(a4),vp_dwidth(a5)
  549.         move.w  pageheight(a4),vp_dheight(a5)
  550.         bra     getchunk
  551. **//**
  552.  
  553. wbenchmsg   dc.l    0       ;contains msg if run from WB
  554. conbuf      dc.l    0       ;readbuffer for CON:-window
  555. remptr      dc.b    0       ;set if -e was specified
  556. resetvar    dc.b    0       ;set if -r was specified
  557. mparm       dc.b    0       ;set if either -e or -l was specified
  558. startup     dc.b    0       ;set if -s was specified
  559. camgf       dc.b    0       ;set if CAMG was found
  560.             dc.b    0       ;make even
  561. memptr      dc.l    0       ;ptr to BODY-chunk
  562. buffer      dc.l    0       ;ptr to readbuffer
  563. handle      dc.l    0       ;handle of IFF-file
  564. dosbase     dc.l    0       ;...
  565. whandle     dc.l    0       ;handle we write to (CLI or CON:)
  566. fname       dc.l    0       ;pointer to filename
  567. dosname     dc.b    'dos.library',0
  568.             even
  569. oname       dc.b    'CON:10/50/620/130/BootPic V1.0 © 1991 by Acki',0
  570.             even
  571. welcome     dc.b    10,27,'[1;32m',' BootPic V1.0 ',27,'[0;31m','©1991 by '
  572.             dc.b    27,'[3;33m','Andreas Ackermann',27,'[0;31m',10
  573.             dc.b    ' This programm is SHAREWARE. If you use it, please send '
  574.             dc.b    27,'[1;32m','5$ or 5DM',27,'[0;31m to:',10
  575.             dc.b    '    Andreas Ackermann',10
  576.             dc.b    '    Lorenz-Summa-Str. 10',10
  577.             dc.b    '    W-8679 Oberkotzau',10
  578.             dc.b    '    GERMANY',10
  579.             dc.b    ' See Doc-File for detailed information !',10,10,0
  580.             even
  581. nmfb        dc.b    'Not enough Memory for BODY-Chunk',10,0
  582.             even
  583. bnf         dc.b    'BODY-Chunk not found',10,0
  584.             even
  585. ncamg       dc.b    'Warning:CAMG-Chunk not found.',10,0
  586.             even
  587. nilbm       dc.b    'This is not an ILBM-Picturefile',10,0
  588.             even
  589. nomem       dc.b    "Couldn't get enough Memory",10,0
  590.             even
  591. fnf         dc.b    "Couldn't open Picturefile",10,0
  592.             even
  593. use         dc.b    "Usage: BootPic -e | -l{ILBM-filename} [-c rgb][-r][-s]",10,0
  594.             even
  595. remt        dc.b    "Removed old BootPicture from list",10,0
  596.             even
  597. ncomp       dc.b    'Picture is not compressed. Save it with DPaint and try again.',10,0
  598.             even
  599. suc         dc.b    'Picture successfully installed. Have fun !',10,0
  600.             even
  601. fail        dc.b    'Memlist Corrupt. Something went totally wrong !',10,0
  602.             even
  603. stext       dc.b    'BootPic already installed. Changed nothing.',10,0
  604.             even
  605. nrem        dc.b    "BootPic was not installed. Couldn't remove it.",10,0
  606.             even
  607. ycom        dc.b    27,'[10;0H',27,'[JYour commands:',0
  608.             even
  609. endwb       dc.b    'Hit RETURN to go on, type anything to end',0
  610.             even
  611.  
  612. * Part of Programm that shows picture after reset
  613.  
  614. begincopy
  615.  
  616. idname      dc.b    'BPic',0,0
  617. idstring    dc.b    'BootPic,©1991 by Acki',0
  618.             dc.b    0,0,0,0,0,0,0,0
  619.  
  620.         movem.l d0-7/a0-6,-(sp)
  621.         move.l  4.w,a6
  622.         move.l  strktptr(pc),a5             ;get ptr of our special structure
  623.         move.l  ml_addr2(a5),a3             ;get ptr of BODY-data
  624.         lea     gfxname(pc),a1
  625.         jsr     _lvooldopenlibrary(a6)
  626.         emove   d0,gfxbase(pc)
  627.         move.l  #readend+8,d0               ;allocate some mem: used for
  628.         move.l  #$10002,d1                  ;replyport and diskio
  629.         jsr     _lvoallocmem(a6)
  630.         move.l  d0,a4
  631.         move.l  d0,-(sp)
  632.         sub.l   a1,a1
  633.         jsr     _lvofindtask(a6)            ;init replyport
  634.         move.l  d0,replyport+$10(a4)
  635.         lea     replyport(a4),a1
  636.         jsr     _lvoaddport(a6)
  637. testagain
  638.         move.l  a4,a1
  639.         clr.l   d0
  640.         clr.l   d1
  641.         lea     trddevice(pc),a0            ;open trackdiskdevice
  642.         jsr     _lvoopendevice(a6)
  643.         tst.l   d0
  644.         bne.s   testagain
  645.         moveq.b #0,d2
  646.         bsr     readboot                    ;check for bootable disk in df0:
  647.         tst.b   d3                          ;[see at readboot what d2 means !]
  648.         beq     cleanup
  649.  
  650. showpic move.l  gfxbase(pc),a6      ;clear all pointers to copperlists
  651.         clr.l   view+4(a5)          ;so that mrgcop knows that it has to take
  652.         clr.l   view+8(a5)          ;new copperlists !
  653.         moveq.w #4,d0
  654.         lea     vp_colormap(a5),a0
  655. cll     clr.l   (a0)+
  656.         dbf     d0,cll
  657.  
  658.         move.w  depth(a5),d2        ;allocate planes; if masking then alloc one
  659.         lea     bm_planes(a5),a2    ;more plane that isn't to be found in
  660.         cmp.b   #1,mask(a5)         ;bm_depth
  661.         beq.s   nomsk
  662.         subq.w  #1,d2
  663. nomsk   move.w  bmw(a5),d0
  664.         move.w  bmh(a5),d1
  665.         jsr     _lvoallocraster(a6)
  666.         move.l  d0,(a2)+
  667.         beq     rasterfail
  668.         dbf     d2,nomsk
  669.         clr.l   (a2)                ;zero-terminate bm_planes cause we'll free
  670.         bsr     unpackbody          ;memory till we find zero
  671.  
  672.         move.l  #32,d0              ;32 is always enough
  673.         jsr     _lvogetcolormap(a6)
  674.         move.l  d0,vp_colormap(a5)
  675.  
  676.         lea     view(a5),a0
  677.         lea     viewport(a5),a1
  678.         jsr     _lvomakevport(a6)
  679.         lea     view(a5),a1
  680.         jsr     _lvomrgcop(a6)      ;generate display
  681.         move.l  34(a6),d7
  682.  
  683.         lea     view(a5),a1
  684.         jsr     _lvoloadview(a6)    ;let's show it
  685.  
  686.         lea     coltab(a5),a2
  687.         lea     viewport(a5),a3
  688.         lea     white(pc),a4
  689.         moveq.w #0,d0
  690.         bsr     fadein              ;fade picture in
  691.         move.l  4.w,a6
  692.         move.l  (sp),a4
  693.         move.b  #1,d2
  694.         bsr     readboot            ;wait for bootable disk
  695.         move.l  gfxbase(pc),a6
  696.         lea     konst(pc),a4
  697.         moveq.w #0,d0
  698.         bsr     fadeout             ;fade to color specified under -c
  699.  
  700.         move.l  vp_colormap(a5),a0  ;free copperlists
  701.         jsr     _lvofreecolormap(a6)
  702.         lea.l   viewport(a5),a0
  703.         jsr     _lvofreevportcoplists(a6)
  704.         move.l   view+4(a5),a0
  705.         jsr     _lvofreecprlist(a6)
  706.         move.l  view+8(a5),a0
  707.         jsr     _lvofreecprlist(a6)
  708.  
  709.         move.l  d7,a1
  710.         jsr     _lvoloadview(a6)    ;show old view
  711.  
  712. rasterfail
  713.         lea     bm_planes(a5),a2
  714. nomsk2  move.l  (a2)+,a0
  715.         tst.l   -4(a2)
  716.         beq.s   meme
  717.         move.w  bmw(a5),d0
  718.         move.w  bmh(a5),d1
  719.         jsr     _lvofreeraster(a6)
  720.         bra.s   nomsk2              ;free planes till we find zero
  721. meme    move.l  34(a6),a0
  722.         move.l  4(a0),a0
  723.         moveq.w #0,d0
  724.         lea     konst(pc),a1        ;set the new color in the old viewport
  725.         move.b  (a1)+,d1
  726.         move.b  (a1)+,d2
  727.         move.b  (a1)+,d3
  728.         jsr     _lvosetrgb4(a6)
  729.  
  730. cleanup move.l  4.w,a6              ;clean up everything we needed to wait for
  731.         move.l  (sp)+,a4            ;disk
  732.         lea     replyport(a4),a1
  733.         jsr     _lvoremport(a6)
  734.         move.l  a4,a1
  735.         jsr     _lvoclosedevice(a6)
  736.         move.l  a4,a1
  737.         move.l  #readend+8,d0
  738.         jsr     _lvofreemem(a6)
  739.         move.l  gfxbase(pc),a1
  740.         jsr     _lvocloselibrary(a6)
  741.         movem.l (sp)+,d0-7/a0-6
  742.         rts
  743.  
  744. * This routines checks for a bootable disk in df0: .
  745. * Result in d3.b : zero if a disk is there, 1 if no bootable disk in drive.
  746. * Flags: if d2.b=1 it will wait until a bootable disk is inserted
  747.  
  748. readboot
  749.         move.l  a4,a1
  750.         lea.l   replyport(a4),a0        ;put replyport int io_request structure
  751.         move.l  a0,14(a1)
  752. readit  move.w  #$5,io_command(a1)      ;declare the buffer to be invalid
  753.         jsr     _lvodoio(a6)
  754.         move.l  #2*512,io_length(a1)
  755.         move.w  #$2,io_command(a1)
  756.         lea     readbuffer(a4),a0       ;read bootblock
  757.         move.l  a0,io_data(a1)
  758.         jsr     _lvodoio(a6)
  759.         tst.l   d0                      ;any errors ?
  760.         bne.s   wfd                     ;if then goto waitfordisk
  761. calcsum lea     readbuffer(a4),a0
  762.         cmp.l   #$444f5300,(a0)         ;check if DOS,0 [could be FFS,0 as well]
  763.         bne.s   wfd
  764.         clr.l   d0
  765.         move.w  #$00ff,d1               ;calculate checksum of bootblock
  766. schleife
  767.         add.l   (a0)+,d0
  768.         bcc.s   nof
  769.         addq.l  #1,d0
  770. nof     dbf     d1,schleife
  771.         not.l   d0
  772.         beq.s   noderr                  ;if zero, disk is bootable
  773.  
  774. wfd     tst.b   d2
  775.         bne.s   motoff                  ;shall we wait for disk ?
  776.         moveq.b #1,d3                   ;if not say there's not a bootable disk
  777.         rts                             ;in drive and return.
  778. ;ndise   cmp.b   #29,31(a4)              ;error
  779. ;        beq.s   wloop
  780. motoff  clr.l   io_length(a1)           ;switch off motor
  781.         move.w  #$9,io_command(a1)
  782.         jsr     _lvodoio(a6)    ;[if io_length=0 motor off, if 1 then on]
  783. remloop bsr     chkdisk
  784.         tst.l   32(a4)          ;wait till no disk in drive
  785.         beq.s   remloop
  786. wloop   bsr     chkdisk
  787.         tst.l   32(a4)          ;wait till next one is inserted
  788.         bne.s   wloop
  789.         bra.s   readit          ;let's look what we got
  790.  
  791. chkdisk move.w  #$e,io_command(a1)
  792.         jsr     _lvodoio(a6)    ;check for disk in df0:
  793.         btst    #6,$bfe001
  794.         bne.s   chkon
  795.         add.l   #4,a7
  796. noderr  clr.l   d3
  797. chkon   rts
  798.  
  799. strktptr    dc.l    0   ;pointer to our special structure
  800. gfxbase     dc.l    0   ;...
  801. gfxname     dc.b    'graphics.library',0
  802.             even
  803. trddevice   dc.b    'trackdisk.device',0
  804.             even
  805. konst       dc.b    $0,$5,$a,0      ;here we put the color specified by -c
  806. white       dc.b    $f,$f,$f,0      ;data for white color.
  807.  
  808. * This routine unpacks the BODY-chunk
  809. * a3 holds a pointer to the packed BODY-data
  810. * a2 must contain pointer to bm_planes
  811. * bm_depth must be put in d4
  812. * bm_bytesperrow could be put in d2 and bm_height could be put in d3
  813. * [to include this in your own programms, it has to be slightly modified.]
  814.  
  815. unpackbody
  816.         movem.l d0-7/a0-6,-(sp)
  817.         moveq.w #0,d5
  818.         move.w  depth(a5),d4
  819.         lea.l   bm_planes(a5),a2
  820.         cmp.b   #1,mask(a5)
  821.         bne.s   unpackline
  822.         addq.w  #1,d4
  823. UnpackLine
  824.         clr.l d6
  825. UnpackPlane
  826.         move.w  bm_bytesperrow(a5),d0
  827.         mulu    d5,d0
  828.         move.l  d0,a4
  829.         asl     #2,d6
  830.         add.l   0(a2,d6.w),a4
  831.         asr     #2,d6
  832.         move.l  a4,a6
  833.         add.w   bm_bytesperrow(a5),a6
  834.         clr.l d0
  835. CheckPacked
  836.         move.b  (a3)+,d0
  837.         cmp.b   #128,d0
  838.         bhi.s   GoOn
  839.         beq.s   CheckFinished
  840. FinishLine
  841.         move.b  (a3)+,(a4)+
  842.         subq.b  #1,d0
  843.         bpl.s   FinishLine
  844.         bra.s   CheckFinished
  845. GoOn    move.b  (a3)+,d1
  846. StoreByte
  847.         move.b  d1,(a4)+
  848.         addq.b  #1,d0
  849.         cmp.b   #1,d0
  850.         bne.s   StoreByte
  851. CheckFinished
  852.         cmp.l   a4,a6
  853.         bhi.s   CheckPacked
  854.         addq.w  #1,d6
  855.         cmp.w   d4,d6
  856.         bne.s   UnpackPlane
  857. GoOnLoop
  858.         addq.w    #1,d5
  859.         cmp.w     bmh(a5),d5
  860.         bne.s     UnpackLine
  861.         movem.l (sp)+,d0-7/a0-6
  862.         rts
  863.  
  864. * reads out the colors of a colormap and stores it in a piece of memory [200
  865. * Bytes required ] in the following form:
  866. * 1st byte r, 2nd byte g and in 3rd byte b. Then the next color appears.
  867. * parms: a2=pointer to memory  a3=pointer to Colormap  a6=gfxbase
  868.  
  869. getcols
  870.  
  871.         movem.l d0-2/a0-2,-(sp)
  872.         moveq.w #0,d2
  873. 1$      move.l  a3,a0
  874.         move.l  d2,d0
  875.         jsr _lvogetrgb4(a6)
  876.         move.b  d0,2(a2)            ;b
  877.         and.b   #%1111,2(a2)
  878.         lsr.w   #4,d0
  879.         move.b  d0,1(a2)            ;g
  880.         and.b   #%1111,1(a2)
  881.         lsr.w   #4,d0
  882.         move.b  d0,(a2)             ;r
  883.         addq.w  #1,d2
  884.         add.l   #3,a2
  885.         cmp.w   2(a3),d2
  886.         bne.s   1$
  887.         movem.l (sp)+,d0-2/a0-2
  888.         rts
  889.  
  890. * fades out a viewport to a specified color [this color must be given in a
  891. * special format:  1st byte r, 2nd g and 3rd b.(4th=0)]
  892. * before fading out it is advisable to save the colors with getcols
  893. * parms: a3=viewport  a4=pointer to color  d0=delaytime (see below)
  894. *        [a5=dosbase] a6=gfxbase
  895.  
  896. fadeout
  897.         movem.l d0-7/a0-6,-(sp)
  898.         move.l  4.w,a6
  899.         move.l  #100,d0
  900.         move.l  #$10001,d1
  901.         jsr _lvoallocmem(a6)
  902.         move.l  d0,a2
  903.         move.l  4(a3),a3
  904.         move.l  56(sp),a6
  905.         bsr getcols
  906.         move.w  2(a3),a3
  907.         move.l  a2,a5
  908. 1$      moveq.b #0,d7
  909.         moveq   #2,d5
  910.         moveq   #0,d6
  911. 2$      moveq   #0,d4
  912.         move.l  a5,a2
  913. 3$      move.b  (a2),d1
  914.         move.b  1(a2),d2
  915.         move.b  2(a2),d3
  916.         move.b  0(a4,d6.w),d0
  917.         cmp.b   0(a2,d6.w),d0
  918.         blt.s   5$
  919.         beq.s   4$
  920.         addq.b  #1,0(a2,d6.w)
  921.         bra.s   6$
  922. 5$      subq.b  #1,0(a2,d6.w)
  923. 6$      moveq.b #1,d7
  924. 4$      move.w  d4,d0
  925.         move.l  44(sp),a0   ;viewport
  926.         move.l  56(sp),a6
  927.         jsr _lvosetrgb4(a6)
  928.         add.l   #3,a2
  929.         addq.w  #1,d4
  930.         cmp.w   a3,d4
  931.         bne.s   3$
  932. ;       move.l  (sp),d1     ;we're before boot up so we can't use dos.lib.
  933. ;       move.l  52(sp),a6   ;so we help ourselves with dbf.
  934. ;       jsr _lvodelay(a6)   ;delay just needed if less then 32 colors.
  935.         move.l  (sp),d0
  936. 10$     dbf d0,10$
  937.         addq.w  #1,d6
  938.         dbf d5,2$
  939.         tst.b   d7
  940.         bne.s   1$
  941.         move.l  4.w,a6
  942.         move.l  a5,a1
  943.         move.l  #100,d0
  944.         jsr _lvofreemem(a6)
  945.         movem.l (sp)+,d0-7/a0-6
  946.         rts
  947.  
  948. * fades in a viewport from a specified color [this color must be given in a
  949. * special format:  1st byte r, 2nd g and 3rd b.(4th=0)]
  950. * parms: a2=pointer to coltab as given by getcols  a3=viewport
  951. * a4=pointer to color  d0=delaytime (see above) [a5=dosbase] a6=gfxbase
  952.  
  953. fadein
  954.         movem.l d0-7/a0-6,-(sp)
  955.         move.l  4(a3),a0
  956.         move.w  2(a0),d0
  957.         move.l  a2,a0
  958.         add.l   #100,a0
  959.         subq.w  #1,d0
  960. 7$      move.b  (a4),(a0)+
  961.         move.b  1(a4),(a0)+
  962.         move.b  2(a4),(a0)+
  963.         dbf d0,7$
  964.         move.l  a2,a5
  965. 1$      move.w  #0,a4
  966.         moveq   #2,d5
  967.         moveq   #0,d6
  968. 2$      moveq   #0,d4
  969.         move.l  a5,a2
  970. 3$      move.b  100(a2),d1
  971.         move.b  101(a2),d2
  972.         move.b  102(a2),d3
  973.         move.b  0(a2,d6.w),d0
  974.         cmp.b   100(a2,d6.w),d0
  975.         beq.s   4$
  976.         blt.s   5$
  977.         addq.b  #1,100(a2,d6.w)
  978.         bra.s   6$
  979. 5$      subq.b  #1,100(a2,d6.w)
  980. 6$      move.w  #1,a4
  981. 4$      move.w  d4,d0
  982.         move.l  a3,a0
  983.         move.l  56(sp),a6   ;gfxbase from Stack
  984.         jsr _lvosetrgb4(a6)
  985.         add.l   #3,a2       ;step to the data of the next colour
  986.         addq    #1,d4       ;count the number of colours that we modified
  987.         move.l  4(a3),a0    ;vport->colormap to a0
  988.         cmp.w   2(a0),d4    ;compare the number of colours with our colour
  989.                         ;counter
  990.         bne.s   3$      ;have we already modified all colours ?If not
  991.                         ;then let's modify the next one
  992. ;       move.l  (sp),d1 ;see above
  993. ;       move.l  52(sp),a6
  994. ;       jsr _lvodelay(a6)
  995.         move.l  (sp),d0
  996. 10$     dbf d0,10$
  997.         addq.w  #1,d6   ;now it's the next component's turn to be changed
  998.         dbf d5,2$   ;we must do this loop three times:once for red,
  999.                     ;once for green and once for blue,
  1000.                     ;so we load d5 with 2!!(3-1) in the beginning
  1001.         cmp.w   #0,a4   ;(tst.w  a4 doesn't work) find out if any changes were
  1002.         bne.s   1$  ;done in this loop,if not then we are ready
  1003.         movem.l (sp)+,d0-7/a0-6 ;clean up stackpointer
  1004.         rts
  1005. endcopy
  1006.  
  1007.     END
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.